package com.lishe.lishe.lishe.http;


import com.lishe.lishe.lishe.bean.UserIntegralBean;
import com.lishe.lishe.retrofit.DataResponseListener;
import com.lishe.lishe.retrofit.RetrofitFactory;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Bin
 */
public class HttpImplements {

    /**
     * 积分查询
     */
    public static void getUserIntegral(String token, final DataResponseListener<UserIntegralBean> listener) {
        RetrofitFactory.create().create(HttpNetApi.class).getUserIntegral(token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UserIntegralBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {}

                    @Override
                    public void onNext(UserIntegralBean bean) {
                        if(bean.getResult()==100 && bean.getErrcode()==0){
                            listener.onSuccess(bean);
                        }else{
                            listener.onFail(bean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {}
                });
    }

}
